/**
 * @file
 */

#include <cstdint>
#include <mocha/api.hpp>
#include <mocha/plugin.hpp>
#include "barista/gl_sdl_graphics_plugin.hpp"
#include "barista/il_image_plugin.hpp"
#include "barista/sdl_event_queue_plugin.hpp"

using namespace mocha;

namespace barista {
	/**
	 *
	 * @return
	 */
	int init() {
		return 1;
	}
	/**
	 *
	 * @return
	 */
	int deinit() {
		return 1;
	}
	/**
	 *
	 * @param fp
	 * @return
	 */
	int register_gl_sdl_graphics_plugin(mocha_plugin_factory_params* fp) {
		mocha_plugin_register_params rp = {
			mocha_plugin_compiled_api_version,
			&gl_sdl_graphics_plugin::create,
			NULL,
			&gl_sdl_graphics_plugin::destroy,
			static_cast<mocha_plugin_language>(gl_sdl_graphics_plugin::interface_language)
		};
		return static_cast<int>(fp->register_object(fp, reinterpret_cast<const plugin_char_t*>(gl_sdl_graphics_plugin_type_name), &rp));
	}
	/**
	 *
	 * @param fp
	 * @return
	 */
	int register_il_image_plugin(mocha_plugin_factory_params* fp) {
		mocha_plugin_register_params rp = {
			mocha_plugin_compiled_api_version,
			&il_image_plugin::create,
			&il_image_plugin::clone,
			&il_image_plugin::destroy,
			static_cast<mocha_plugin_language>(il_image_plugin::interface_language)
		};
		return static_cast<int>(fp->register_object(fp, reinterpret_cast<const plugin_char_t*>(il_image_plugin_type_name), &rp));
	}
}
extern "C" {
/**
 *
 * @return
 */
MOCHA_PLUGIN_API std::int32_t mocha_plugin_deinit_plugin() {
	return barista::deinit();
}
/**
 *
 * @param fp
 * @param result
 * @return
 */
MOCHA_PLUGIN_API mocha_plugin_deinit_func_t mocha_plugin_init_plugin(mocha_plugin_factory_params* fp, std::int32_t* rc) {
	if (!(*rc = barista::init())) {
		mocha_plugin_deinit_plugin(); // Must clean up here, since the core can't call this itself.
		return NULL;
	}
	return &mocha_plugin_deinit_plugin;
}
} // extern "C"

